package org.example.seatunnel;

import com.typesafe.config.Config;
import org.example.seatunnel.model.SourceResModel;

import java.util.ArrayList;
import java.util.List;

public class SeatunnelSourceWrapper {

    static List<SeatunnelSource> sourceList = new ArrayList<>();

    static {
        sourceList.add(new SeatunnelJdbcSource());
    }

    private static SeatunnelSource getSeatunnelSource(Config config){
        for (SeatunnelSource source : sourceList) {
            if(source.isSupport(config)){
                return source;
            }
        }

        System.out.println(config);

        throw new RuntimeException("配置未能找到解析器"+config.entrySet().stream().findFirst().get().getKey());

    }

   public  static SourceResModel parse(Config config){
       SeatunnelSource seatunnelSource = getSeatunnelSource(config);

       SourceResModel sourceResModel = seatunnelSource.parse(config);

       return sourceResModel;
   }

}
